import 'package:flutter/services.dart';

class DoNotDisturbService {
  static const MethodChannel _channel = MethodChannel('com.example.myapp/do_not_disturb');

  /// 启用免打扰模式
  static Future<bool> enableDoNotDisturb() async {
    try {
      final bool result = await _channel.invokeMethod('enableDoNotDisturb');
      return result;
    } on PlatformException catch (e) {
      print('启用免打扰失败: ${e.message}');
      rethrow;
    }
  }

  /// 关闭免打扰模式
  static Future<bool> disableDoNotDisturb() async {
    try {
      final bool result = await _channel.invokeMethod('disableDoNotDisturb');
      return result;
    } on PlatformException catch (e) {
      print('关闭免打扰失败: ${e.message}');
      rethrow;
    }
  }

  /// 检查免打扰模式是否启用
  static Future<bool> isDoNotDisturbEnabled() async {
    try {
      final bool result = await _channel.invokeMethod('isDoNotDisturbEnabled');
      return result;
    } on PlatformException catch (e) {
      print('检查免打扰状态失败: ${e.message}');
      rethrow;
    }
  }

  /// 检查通知策略访问权限
  static Future<bool> checkNotificationPolicyPermission() async {
    try {
      final bool result = await _channel.invokeMethod('checkNotificationPolicyPermission');
      return result;
    } on PlatformException catch (e) {
      print('检查权限状态失败: ${e.message}');
      rethrow;
    }
  }

  /// 打开通知策略设置页面
  static Future<bool> openNotificationPolicySettings() async {
    try {
      final bool result = await _channel.invokeMethod('openNotificationPolicySettings');
      return result;
    } on PlatformException catch (e) {
      print('打开设置页面失败: ${e.message}');
      rethrow;
    }
  }
}
